<?php
namespace Home\Controller;
use Model\DrawModel;
use Model\GameRoleModel;
use Think\Controller;
use \Model\UserModel;
class AjaxController extends Controller {
    function is_playing($uid){

        $this->ajaxReturn(DrawModel::is_playing($uid)?true:false);
    }
    //修改房间准备状态
    function set_ready(){
        $user_uid=I("post.user_uid");
        $room_uid=I("post.room_uid");
        $room=D('room')->where("uid=".$room_uid)->find();
        $ready_users=explode(",",$room['has_ready_uids']);

        array_push($ready_users,$user_uid);
//        var_dump($ready_users);exit;
        $ready_users=array_unique(array_filter($ready_users));//去空去重
        $db=new \Model\DbModel();
        $res=$db->updatedata("room",array("has_ready_uids"=>implode(",",$ready_users)),"uid=".$room_uid);
        $this->ajaxReturn(array("error"=>1,"msg"=>$res));
    }
    function start(){
        $host_uid=I("post.host_uid");
        $room_uid=I("post.room_uid");
//        $this->ajaxReturn($room_uid);
        $roomhost=D('room')->field("host_uid")->where("uid=".$room_uid)->find()['host_uid'];
        if($host_uid!=$roomhost)
            $this->ajaxReturn(array("error"=>0,"course"=>"你不是房主"));
//        DrawModel::start($room_uid);
//        if(!DrawModel::start($room_uid))
//            $this->ajaxReturn(array("error"=>0,"course"=>"全部人准备后才可以开始游戏"));
        $this->ajaxReturn(DrawModel::start($room_uid));
    }
}